from django.core import validators
from django.db import models

# Create your models here.


class Author(models.Model):
    """
    作者模型
    """
    name = models.CharField(max_length=100)
    age = models.IntegerField()
    email = models.EmailField()
    class Meta:
        db_table = 'front_author'


class Publisher(models.Model):
    """出版社模型"""
    name = models.CharField(max_length=100)


class Book(models.Model):
    """
     图书模型
    """
    name = models.CharField(max_length=100)
    pages = models.IntegerField()
    price = models.FloatField()
    rating = models.FloatField()
    author=models.ForeignKey(Author, on_delete=models.CASCADE)
    publisher = models.ForeignKey(Publisher, on_delete=models.CASCADE)

class BookOrder(models.Model):
    """图书订单模型"""
    book=models.ForeignKey(Book, on_delete=models.CASCADE)
    price=models.FloatField()
    class Meta:
        db_table = 'front_book_order'

# 用户
class User(models.Model):
    username = models.CharField(max_length=100)
    password = models.CharField(max_length=100)
    tel = models.CharField(max_length=11)
    email = models.EmailField()


class Article(models.Model):
    title = models.CharField(max_length=200,validators=[validators.MinLengthValidator(limit_value=2)])
    content = models.TextField(validators=[validators.MinLengthValidator(limit_value=3)])
    created_time = models.DateTimeField(auto_now_add=True)
    # blank=True，只是表单验证时允许为空，不代表据摩可以为空
    # category = models.CharField(max_length=255,blank=True)